package fr.ece.ing4.ams;

import java.util.HashSet;
import java.util.Set;

public final class SystemManager {

	private static Set<airport> airports = new HashSet<airport>();
	private SystemManager() {
		super();
	}
	
	/**
	 * returns an instance of airport
	 * @param code airport code must be 3 char long
	 * @return the new airport
	 * @throws AMSexeption 
	 */
	public static airport createairport(String code) throws AMSexeption
	{
		if(code.length() != 3)
			throw new IllegalArgumentException("code 3 chars long");
		airport ap = new airport(code);
		 if (!airports .add(ap))
		 {
			ap = null;	 
			 throw new AMSexeption ("airport exists");
		 }
		return ap;
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			airport cdg = createairport("CDG");
			//airport cdg1 = createairport("CDG");
			System.out.println(airports);
		} catch (AMSexeption e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
